console.log('加载全局函数');
/****radar_index****/
function refreshRadar(){
	 $$('#radar_index .targetloc').each(function(){
		 var targetid = $$(this).data('targetid');
		 //console.log(targetid);
		 var icon = devices[targetid]['icon'];
		 //计算位置
		 var rssi = parseFloat($$(this).data('rssi'));
		 var A = parseFloat(devices[targetid]['paramA']);
	     var n = parseFloat(devices[targetid]['paramN']);
	     var mi = (parseFloat(Math.abs(rssi))-A)/parseFloat(10)/n;
		 var d = Math.pow(10,mi);
		 
		 var r,top,left;
		 var num = devices[targetid]['randomnum']//一个0到1之间的随机数
		 var pi = Math.PI;
		 var angle = 2*pi*num;
		 var sin = Math.sin(angle);
		 var cos = Math.cos(angle);
		 
		 if(d<5 || d==5){
			 r = 50;
			 top = r*sin+150-15;
			 left = r*cos+150-15;
			 top = top.toString()+'px';
			 left = left.toString()+'px';
		 }else if(d>5 && d<10 || d==10){
			 r = 100;
			 top = r*sin+150-15;
			 left = r*cos+150-15;
			 top = top.toString()+'px';
			 left = left.toString()+'px';
		 }else{
			 r = 130;
			 top = r*sin+150-15;
			 left = r*cos+150-15;
			 top = top.toString()+'px';
			 left = left.toString()+'px';
		 }
		 //console.log(rssi,d,top,left);
		 $$(this).css({
			 'top':top,
			 'left':left,
			 'background':'url('+icon+') no-repeat',
			 'background-size':'30px 30px',
		     'background-position':'center'
		 });
		 $$(this).show();
	 });
}

/****fate****/
  var timer1,timer2,timer3;
  var startdeg1 = 0;
  var startdeg2 = 0;
  var startdeg3 = 0;
  
  function rotate1(){
	  if(startdeg1 == 360){
		  startdeg1 = 0;
	  }
	  $$('#fate .img1').transform('rotateX('+startdeg1+'deg)');
	  startdeg1 +=5;
  }
  function rotate2(){
	  if(startdeg2 == 360){
		  startdeg2 = 0;
	  }
	  $$('#fate .img2').transform('rotateX('+startdeg2+'deg)');
	  startdeg2 +=5;
  }
  function rotate3(){
	  if(startdeg3 == 360){
		  startdeg3 = 0;
	  }
	  $$('#fate .img3').transform('rotateX('+startdeg3+'deg)');
	  startdeg3 +=5;
  }
  
  function startRotate(timer,rotateSpeed){
	  //console.log(startdeg);
	  switch(timer){
		  case '1':
			  timer1 = setInterval("rotate1()",rotateSpeed);
			  break;
		  case '2':
			  timer2 = setInterval("rotate2()",rotateSpeed);
			  break;
		  case '3':
			  timer3 = setInterval("rotate3()",rotateSpeed);
			  break;
		  default:
	  }
	  
  }
  function stopRotate(timer){
	  var num = parseFloat(Math.random()*100);//得到一个0到1之间的随机数
	  //console.log(num);
	  if(num < parseFloat(25) || num == parseFloat(25)){
		  var res = true;
	  }else if(num > parseFloat(25) && num < parseFloat(50)  || num == parseFloat(50)){
		  var res = false;
	  }else if(num > parseFloat(50) && num < parseFloat(75)  || num == parseFloat(75)){
		  var res = true;
	  }else{
		  var res = false;
	  }
	  
	  switch(timer){
		  case '1':
			  clearInterval(timer1);
			  $$('#fate .img1').hide();
			  $$('#fate .img1').transform('rotateX(0deg)');
			  startdeg1 = 0;
			  if(res){
				  $$('#fate .img1.up').show();
				  $$('.fate-res').data('img1res','01');
			  }else{
				  $$('#fate .img1.down').show();
				  $$('.fate-res').data('img1res','02');
			  }
			  break;
		  case '2':
			  clearInterval(timer2);
			  $$('#fate .img2').hide();
			  $$('#fate .img2').transform('rotateX(0deg)');
			  startdeg2 = 0;
			  if(res){
				  $$('#fate .img2.up').show();
				  $$('.fate-res').data('img2res','01');
			  }else{
				  $$('#fate .img2.down').show();
				  $$('.fate-res').data('img2res','02');
			  }
			  break;
		  case '3':
			  clearInterval(timer3);
			  $$('#fate .img3').hide();
			  $$('#fate .img3').transform('rotateX(0deg)');
			  startdeg3 = 0;
			  if(res){
				  $$('#fate .img3.up').show();
				  $$('.fate-res').data('img3res','01');
			  }else{
				  $$('#fate .img3.down').show();
				  $$('.fate-res').data('img3res','02');
			  }
			  break;
		  default:
	  }
  }